//
//  CODetailAnswerTableViewCell.swift
//  CocoProject
//
//  Created by Ruthless on 2023/8/23.
//

import UIKit

class CODetailAnswerTableViewCell: UITableViewCell {
    var model: COQADetailAnswerModel? {
        didSet {
            guard let model = model else {
                return
            }
            
            avatar.kf.setImage(with: URL(string: model.avatar))
            nameLabel.text = model.name
            timeLabel.text = model.time
            contentLabel.text = model.content
        }
    }
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .none
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func configUI() {
        backgroundColor = .rgba(17, 7, 41, 1)
        contentView.addSubview(avatar)
        contentView.addSubview(nameLabel)
        contentView.addSubview(timeLabel)
        contentView.addSubview(contentLabel)
        contentView.addSubview(lineView)
        
        avatar.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(20)
            make.top.equalToSuperview().offset(18)
            make.width.height.equalTo(30)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(avatar.snp.right).offset(5)
            make.top.equalTo(avatar.snp.top).offset(0)
        }
        
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(avatar.snp.right).offset(5)
            make.bottom.equalTo(avatar.snp.bottom).offset(0)
        }
        
        contentLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(20)
            make.top.equalTo(avatar.snp.bottom).offset(16)
        }
        
        lineView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview().offset(0)
            make.top.equalTo(contentLabel.snp.bottom).offset(15)
            make.height.equalTo(1)
        }
    }
    
    private lazy var avatar: UIImageView = {
        let imgV = UIImageView()
        imgV.layer.masksToBounds = true
        imgV.layer.cornerRadius = 15
        return imgV
    }()
    
    private lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(15)
        label.textColor = .white
        return label
    }()

    private lazy var timeLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(12)
        label.textColor = .white.withAlphaComponent(0.5)
        return label
    }()
    
    private lazy var contentLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(15)
        label.textColor = .white
        label.numberOfLines = 0
        return label
    }()
    
    private lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = .white.withAlphaComponent(0.15)
        return view
    }()
}
